package vista;

import com.gestion.modelo.dominio.ItemPedido;
import com.gestion.modelo.dominio.Pedido;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import vista.modelo.ModeloTablaItemPedido;

/**
 * @author Mauri@<itsoluciones.com.ar>
 */
public class JIFPedido extends javax.swing.JInternalFrame {

    /**
     * Creates new form JIFPedido
     */
    public JIFPedido() {
        //System.out.println(this.toString());
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLApellido = new javax.swing.JLabel();
        jLDireccion = new javax.swing.JLabel();
        jLLocalidad = new javax.swing.JLabel();
        jLProvincia = new javax.swing.JLabel();
        jLNombre = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLDireccionEntrega = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTItemPedido = new javax.swing.JTable();
        jBPagoVerificado = new javax.swing.JButton();
        jBCancelarPago = new javax.swing.JButton();
        jBEntregarPedido = new javax.swing.JButton();
        jBCancelarPedido = new javax.swing.JButton();
        jBPedidoEntregado = new javax.swing.JButton();
        jBPedidoNoEntregado = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLNumeroPedido = new javax.swing.JLabel();
        jLFechaPedido = new javax.swing.JLabel();
        jLTotalPedido = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLTipo_Pago = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLEstadoPedido = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLPagoVerificado = new javax.swing.JLabel();
        jBCerrar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel2.setText("Datos del Cliente");

        jLabel3.setText("Nombre");

        jLabel4.setText("Apellido");

        jLabel5.setText("Dirección");

        jLabel6.setText("Localidad");

        jLabel7.setText("Provincia");

        jLApellido.setText(".................");

        jLDireccion.setText(".................");

        jLLocalidad.setText(".................");

        jLProvincia.setText(".................");

        jLNombre.setText(".................");

        jLabel8.setText("Dirección de Entrega");

        jLDireccionEntrega.setText(".................");

        jLabel9.setText("Productos");

        jTItemPedido.setModel(new ModeloTablaItemPedido(
            new ArrayList<ItemPedido>())

    );
    jScrollPane2.setViewportView(jTItemPedido);

    jBPagoVerificado.setText("Pago Verificado");

    jBCancelarPago.setText("Cancelar Pago");

    jBEntregarPedido.setText("Entregar Pedido");

    jBCancelarPedido.setText("Cancelar Pedido");

    jBPedidoEntregado.setText("Pedido Entregado");

    jBPedidoNoEntregado.setText("Pedido No Entregado");

    jLabel10.setText("Datos Pedidos");

    jLabel11.setText("Número");

    jLabel12.setText("Fecha");

    jLabel13.setText("Total");

    jLNumeroPedido.setText(".................");

    jLFechaPedido.setText(".................");

    jLTotalPedido.setText(".................");

    jLabel1.setText("Tipo de Pago");

    jLTipo_Pago.setText(".................");

    jLabel14.setText("Estado del Pedido:");

    jLEstadoPedido.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
    jLEstadoPedido.setText(".................");

    jLabel15.setText("Estado del Pago:");

    jLPagoVerificado.setText(".................");

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(61, 61, 61)
                    .addComponent(jLabel10))
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel11)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel12)
                            .addGap(14, 14, 14)))
                    .addGap(19, 19, 19)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLNumeroPedido, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLFechaPedido, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(jLabel13)
                    .addGap(38, 38, 38)
                    .addComponent(jLTotalPedido, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addGap(132, 132, 132)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel14)
                .addComponent(jLabel15)
                .addComponent(jLabel1))
            .addGap(18, 18, 18)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLTipo_Pago)
                .addComponent(jLPagoVerificado)
                .addComponent(jLEstadoPedido, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(0, 0, Short.MAX_VALUE))
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addComponent(jLabel10)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel11)
                .addComponent(jLNumeroPedido, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel12)
                .addComponent(jLFechaPedido, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLTotalPedido, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addContainerGap())
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel1)
                .addComponent(jLTipo_Pago))
            .addGap(31, 31, 31)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel14)
                .addComponent(jLEstadoPedido))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel15)
                .addComponent(jLPagoVerificado)))
    );

    jBCerrar.setText("Cerrar");
    jBCerrar.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jBCerrarActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jLabel2)
                    .addGap(71, 71, 71)
                    .addComponent(jLabel9))
                .addComponent(jBCerrar)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jBPagoVerificado)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jBCancelarPago)
                            .addGap(18, 18, 18)
                            .addComponent(jBEntregarPedido)
                            .addGap(18, 18, 18)
                            .addComponent(jBCancelarPedido))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jBPedidoEntregado)
                            .addGap(18, 18, 18)
                            .addComponent(jBPedidoNoEntregado))))
                .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel4)
                                .addComponent(jLabel3)
                                .addComponent(jLabel5)
                                .addComponent(jLabel6)
                                .addComponent(jLabel7))
                            .addGap(18, 18, 18)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLLocalidad)
                                .addComponent(jLProvincia)
                                .addComponent(jLDireccion)
                                .addComponent(jLNombre)
                                .addComponent(jLApellido)))
                        .addComponent(jLabel8)
                        .addComponent(jLDireccionEntrega, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(50, 50, 50)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel2)
                .addComponent(jLabel9))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jLNombre))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4)
                        .addComponent(jLApellido))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(jLDireccion))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel6)
                        .addComponent(jLLocalidad))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7)
                        .addComponent(jLProvincia))
                    .addGap(18, 18, 18)
                    .addComponent(jLabel8)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jLDireccionEntrega))
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(47, 47, 47)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jBPagoVerificado)
                .addComponent(jBCancelarPago)
                .addComponent(jBEntregarPedido)
                .addComponent(jBCancelarPedido))
            .addGap(15, 15, 15)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jBPedidoEntregado)
                .addComponent(jBPedidoNoEntregado)
                .addComponent(jBCerrar))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCerrarActionPerformed
        this.dispose();        // TODO add your handling code here:
    }//GEN-LAST:event_jBCerrarActionPerformed

    public void agregarVerificarPagoListener(ActionListener verificarPagoListener) {
        this.jBPagoVerificado.addActionListener(verificarPagoListener);
    }

    public void agregarCancelarPagoListener(ActionListener cancelarPagoListener) {
        this.jBCancelarPago.addActionListener(cancelarPagoListener);
    }

    public void agregarEntregarPedidoListener(ActionListener entregarPedidoListener) {
        this.jBEntregarPedido.addActionListener(entregarPedidoListener);
    }

    public void agregarPedidoEntregadoListener(ActionListener pedidoEntregado) {
        this.jBPedidoEntregado.addActionListener(pedidoEntregado);
    }

    public void agregarPedidoNoEntregadoListener(ActionListener pedidoNoEntregado) {
        this.jBPedidoNoEntregado.addActionListener(pedidoNoEntregado);
    }

    public void agregarCancelarPedidoListener(ActionListener cancelarPedido) {
        this.jBCancelarPedido.addActionListener(cancelarPedido);
    }

    public void llenarDatos(Pedido pedido) {
        jLApellido.setText(pedido.getCliente().getApellido());
        jLNombre.setText(pedido.getCliente().getNombre());
        jLDireccion.setText(pedido.getCliente().getDireccion());
        jLLocalidad.setText(pedido.getCliente().getLocalidad());
        jLProvincia.setText(pedido.getCliente().getProvincia());
        jLDireccionEntrega.setText(pedido.getDireccion_Entrega());

        jLNumeroPedido.setText(Long.toString(pedido.getId()));
        jLTotalPedido.setText(Float.toString(pedido.getTotal()));

        jLFechaPedido.setText(pedido.fechaStringValue());

        jLTipo_Pago.setText(pedido.getTipopago().toString());
        jLEstadoPedido.setText(pedido.getEstado().toString());

        if (!(pedido.getPago() == null) && (pedido.getPago().isVerificado() == true)) {
            jLPagoVerificado.setText("Verificado");
        } else {
            jLPagoVerificado.setText("No Verificado");
        }

        ((ModeloTablaItemPedido) this.jTItemPedido.getModel()).setListaItemPedido(pedido.getItemPedidos());

    }

    public void botonesUsuario() {
        jBPagoVerificado.setEnabled(false);
        jBCancelarPago.setEnabled(false);
    }

    public void botonesAdmin() {
        //jBEntregarPedido.setEnabled(false);
        jBPedidoNoEntregado.setEnabled(false);
        jBPedidoEntregado.setEnabled(false);
    }

    public void deshabilitarBotonPago() {
        jBPagoVerificado.setEnabled(false);
        jBCancelarPago.setEnabled(true);
    }

    public void botonEntregar(boolean b) {
        jBEntregarPedido.setEnabled(b);
        //System.out.println("jBEntregarPedido "+jBEntregarPedido.isEnabled());
    }

    public void botonPagoVerificado(boolean b) {
        jBPagoVerificado.setEnabled(b);
    }

    public void botonCancelarPago(boolean b) {
        jBCancelarPago.setEnabled(b);
        //System.out.println("jBCancelarPago "+jBCancelarPago.isEnabled());
    }

    public void botonCancelarPedido(boolean b) {
        jBCancelarPedido.setEnabled(b);
    }

    public void botonEntregado(boolean b) {
        jBPedidoEntregado.setEnabled(b);
    }

    public void botonNoEntregado(boolean b) {
        jBPedidoNoEntregado.setEnabled(b);
    }

    public void botonCerrar() {
        this.dispose();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBCancelarPago;
    private javax.swing.JButton jBCancelarPedido;
    private javax.swing.JButton jBCerrar;
    private javax.swing.JButton jBEntregarPedido;
    private javax.swing.JButton jBPagoVerificado;
    private javax.swing.JButton jBPedidoEntregado;
    private javax.swing.JButton jBPedidoNoEntregado;
    private javax.swing.JLabel jLApellido;
    private javax.swing.JLabel jLDireccion;
    private javax.swing.JLabel jLDireccionEntrega;
    private javax.swing.JLabel jLEstadoPedido;
    private javax.swing.JLabel jLFechaPedido;
    private javax.swing.JLabel jLLocalidad;
    private javax.swing.JLabel jLNombre;
    private javax.swing.JLabel jLNumeroPedido;
    private javax.swing.JLabel jLPagoVerificado;
    private javax.swing.JLabel jLProvincia;
    private javax.swing.JLabel jLTipo_Pago;
    private javax.swing.JLabel jLTotalPedido;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTItemPedido;
    // End of variables declaration//GEN-END:variables
}
